/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package minesweeper;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JFrame;

import javax.swing.text.DefaultHighlighter.DefaultHighlightPainter;
import javax.swing.text.Highlighter;

/**
 *
 * @author Gustavo
 */
public class logReader extends javax.swing.JFrame
{

    /**
     * Creates new form logReader
     */
    DefaultHighlightPainter whitePainter = new DefaultHighlightPainter(Color.WHITE);
    DefaultHighlightPainter grayPainter = new DefaultHighlightPainter(Color.GRAY);
    DefaultHighlightPainter greenPainter = new DefaultHighlightPainter(Color.GREEN);
    DefaultHighlightPainter bluePainter = new DefaultHighlightPainter(Color.BLUE);
    DefaultHighlightPainter redPainter = new DefaultHighlightPainter(Color.RED);
    DefaultHighlightPainter yellowPainter = new DefaultHighlightPainter(Color.YELLOW);
    DefaultHighlightPainter orangePainter = new DefaultHighlightPainter(Color.ORANGE);
    DefaultHighlightPainter pinkPainter = new DefaultHighlightPainter(Color.PINK);
    DefaultHighlightPainter cyanPainter = new DefaultHighlightPainter(Color.CYAN);
    DefaultHighlightPainter magentaPainter = new DefaultHighlightPainter(Color.MAGENTA);

    public logReader()
    {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public void setLog(ArrayList<String> log)
    {
        jTLog.setText(log.toString());
        Highlighter highlighter = new MyHighlighter();
        jTLog.setHighlighter(highlighter);
        int begin = 0, end = 0;
        jTLog.setText("");
        String concat = "";
        int lastIndex = 0;
        for (String line : log)
        {
            concat += line + "\n";
        }
        try
        {
            jTLog.setText(concat);

            lastIndex = 0;
            while (concat.indexOf("Begin Auto Solve", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Begin Auto Solve", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, greenPainter);
            }

            lastIndex = 0;
            while (concat.indexOf("Remains are Free At (X,Y)", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Remains are Free At (X,Y)", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, bluePainter);
            }
            lastIndex = 0;
            while (concat.indexOf("Squares Selected at X-Y", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Squares Selected at X-Y", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, grayPainter);
            }
            
            lastIndex = 0;
            while (concat.indexOf("Remains are Bomb At (X,Y)", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Remains are Bomb At (X,Y)", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, yellowPainter);
            }

            lastIndex = 0;
            while (concat.indexOf("Flags Set at X-Y", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Flags Set at X-Y", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, grayPainter);
            }

            lastIndex = 0;
            while (concat.indexOf("Random Click At (X,Y)", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Random Click At (X,Y)", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                System.out.println("begin " + begin);
                System.out.println("end " + end);
                jTLog.getHighlighter().addHighlight(begin, end, orangePainter);
            }
            
            lastIndex = 0;
            while (concat.indexOf("REVEALING BOMBS - END OF GAME", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("REVEALING BOMBS - END OF GAME", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, redPainter);
            }
            
            lastIndex = 0;
            while (concat.indexOf("Clicked At X-Y", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Clicked At X-Y", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, pinkPainter);
            }
            
            lastIndex = 0;
            while (concat.indexOf("Revealing Zeroes At X-Y", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("Revealing Zeroes At X-Y", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, cyanPainter);
            }
            
            lastIndex = 0;
            while (concat.indexOf("CheatClick X-Y", lastIndex) > -1)
            {
                //lastIndex = concat.indexOf("Remains are Free At (X,Y)",lastIndex);
                begin = concat.indexOf("CheatClick X-Y", lastIndex);
                end = concat.indexOf("\n", begin);
                lastIndex = end;
                jTLog.getHighlighter().addHighlight(begin, end, magentaPainter);
            }
            
            
            



        } catch (Exception e)
        {
            e.printStackTrace();
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTLog = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Log"));

        jScrollPane1.setViewportView(jTLog);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTLog;
    // End of variables declaration//GEN-END:variables
}
